//
// Created by tacom on 22-8-31.
//
#include "MatGenerate.h"
#include "opencv2/opencv.hpp"
#include "pybind11/pybind11.h"
#include "NumPyMatConvert.h"
#include "pybind11/numpy.h"

pybind11::array_t<unsigned char> CudaMatRead(pybind11::array_t<unsigned char>& input){
    cv::Mat src = NumPyMatConvert::Ny8UC3ToMat(input);
    cv::cuda::GpuMat cu_src;
    cu_src.upload(src);
    MatGenerateWrapper(cu_src);
    cv::Mat dst;
    cu_src.download(dst);
    return NumPyMatConvert::Mat8UC3ToNumpy(dst);
}

PYBIND11_MODULE(CudaMatRead, m){
    m.def("CudaMatRead", &CudaMatRead, "init img from cuda");
}



int main(){
    int width = 400, height = 400;
    cv::Mat src, dst;
    cv::cuda::GpuMat cu_src;

    // read
    cv::Mat m = cv::Mat::zeros(height, width, CV_8UC3);

    // upload
    cu_src.upload(m);
    MatGenerateWrapper(cu_src);

    // download
    cu_src.download(dst);

    // show
    cv::imshow("img", dst);
    cv::waitKey(0);


}